import DictComponent from '@/plugins/dict'
import { getDict } from '@/api/dict';
import Vue from "vue";
import { setTimeout } from 'core-js';

console.log("安装字典插件")

export default function install(Vue, options) {
    Vue.mixin({
        data: function () {
            let dicts = this.$options.dicts;
            if (dicts instanceof Array) {
                let dict = {}
                for (let index in dicts) {
                    dict[dicts[index]] = []
                }
                return dict
            } else {
                return {
                }
            }
        },
        created: function () {
            if (this.$options.dicts instanceof Array && this.$options.dicts.length > 0) {
                const dicts = this.$options.dicts;
                for (let index in dicts) {
                    let dictName = dicts[index];
                    getDict(dictName).then(data => {
                        console.log(dictName + ":%O", data.data)
                        this[dictName] = data.data;
                    });
                }
            }
        }
    })
}

Vue.use(DictComponent, { name: "DictComponent" })